package com.gage.controller.admin;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gage.controller.base.BaseController;
import com.gage.commons.ueditor.ActionEnter;
/**
 * 上传图片的controller
 * @author lkr
 *
 */
@Controller
@RequestMapping(value="/ueditor")
public class UeditorController extends BaseController{
	@RequestMapping("/config")
    public void config(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("application/json");
        String rootPath = request.getSession()
                .getServletContext().getRealPath("/");
        String action = request.getParameter("action");
        try {
            String exec = new ActionEnter(request, rootPath).exec();
            if( action!=null && 
                    (action.equals("listfile") || action.equals("listimage") ) ){
                     rootPath = rootPath.replace("\\", "/");
                     exec = exec.replaceAll(rootPath, "/");
                 }
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
    }
}
